﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
namespace Nirvana
{
    [Serializable]
    public sealed class CheckAudio
    {
        private enum MonoMode
        {
            [EnumLabel("Not Check")]
            NotCheck,
            [EnumLabel("Force Mono")]
            ForceMono,
            [EnumLabel("Force Not")]
            ForceNot
        }

        [SerializeField]
        [EnumLabel]
        [Tooltip("The mono mode.")]
        private MonoMode monoMode;

        private enum LoadMode
        {
            [EnumLabel("Not Check")]
            NotCheck,
            [EnumLabel("Force Load Background")]
            ForceLoadBackground,
            [EnumLabel("Force Not")]
            ForceNot
        }
        [Tooltip("The load mode.")]
        [EnumLabel]
        [SerializeField]
        private LoadMode loadMode;

        private enum PreloadMode
        {
            [EnumLabel("Not Check")]
            NotCheck,
            [EnumLabel("Force Preload Audio Data")]
            ForcePreloadAudioData,
            [EnumLabel("Force Not")]
            ForceNot
        }
        [SerializeField]
        [Tooltip("The preload mode.")]
        [EnumLabel]
        private PreloadMode preloadMode;

        [Tooltip("The max length limit for audios.")]
        [SerializeField]
        private float maxLength = -1f;

        [SerializeField]
        [Tooltip("The max frequency limit for audios.")]
        private int maxFrequency = -1;


        public void CheckAudioImporter(AssetCheckReport report,AudioImporter importer)
        {
            if (this.monoMode == MonoMode.ForceMono)
            {
                if (!importer.forceToMono)
                {
                    report.ShowWarnInfo("The audio is not force to mono, but it is required to.");
                }
                else if (this.monoMode == MonoMode.ForceNot && importer.forceToMono)
                {
                    report.ShowWarnInfo("The audio is force mono, but it is required not to.");
                }
                if (this.loadMode == LoadMode.ForceLoadBackground)
                {
                    if (!importer.loadInBackground)
                    {
                        report.ShowWarnInfo("The audio is not load in background, but it is required to.");
                    }
                }
                else if (this.loadMode == LoadMode.ForceNot && importer.loadInBackground)
                {
                    report.ShowWarnInfo("The audio is load in background, but it is required not to.");
                }

                if (this.preloadMode == PreloadMode.ForcePreloadAudioData)
                {
                    if (!importer.defaultSampleSettings.preloadAudioData)
                    {
                        report.ShowWarnInfo("The audio is not preload data, but it is required to.");
                    }
                }
                else if (this.preloadMode == PreloadMode.ForceNot && importer.defaultSampleSettings.preloadAudioData)
                {
                    report.ShowWarnInfo("The audio is preload data, but it is required not to.");
                }
            }

        }

        public void CheckAudioClip(AssetCheckReport report,AudioClip clip)
        {
            if (this.maxLength > 0f && clip.length > this.maxLength)
            {
                report.ShowWarnInfo("The audio length is {0}s, longer than {1}.",clip.length,this.maxLength);
            }
            if (this.maxFrequency > 0 && clip.frequency > this.maxFrequency)
            {
                report.ShowWarnInfo("The audio frequency is {0}s, more than {1}.", clip.frequency,this.maxFrequency);
            }
        }

    }


}
